package com.genwangsun.nettydemo.config.redisInfra;

import com.genwangsun.nettydemo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RFuture;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RedisMessageListener {
    @Autowired
    private RedissonClient redissonClient;

    public void subscribe() {
        log.info("RedisMessageListener subscribe start");
        RTopic topic = redissonClient.getTopic("myTopic");
        RFuture<Integer> listenerFuture = topic.addListenerAsync(User.class, (charSequence, user) -> {
            log.info("channel -> {}, message -> {}" , charSequence.toString() ,user);
        });
    }
}
